<?php

declare (strict_types=1);

namespace App\Model;

use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\Relations\HasOne;

/**
 * Class Aftersale
 * @package App\Model
 */
class Aftersale extends Model
{
    protected $primaryKey = 'af_id';

    public $timestamps = false;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_aftersale';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['user_id' => 'string'];

    /**
     * 关联订单信息-物流信息
     * @return HasOne
     */
    public function with_order()
    {
        return $this->hasOne(FlyOrder::class, 'order_id', 'order_id')
            ->with('with_delivery_log');
    }

    /**
     * 关联售后单对应订单商品
     * @return HasMany
     */
    public function with_products()
    {
        return $this->hasMany(AftersaleProduct::class, 'af_id', 'af_id')
            ->with(['with_order_products']);
    }

    /**
     * 获取用户地址
     * @return HasOne
     */
    public function with_user_address()
    {
        return $this->hasOne(FlyAddress::class, 'id', 'user_address_id');
    }

    /**
     * 获取商家地址
     * @return HasOne
     */
    public function with_shop_address()
    {
        return $this->hasOne(ShopSendAddress::class, 'id', 'shop_address_id');
    }

    /**
     * 获取商家变更地址
     * @return HasOne
     */
    public function with_shop_change_address()
    {
        return $this->hasOne(ShopSendAddress::class, 'id', 'shop_change_address_id');
    }
}